package com.suxin.netty.remoting;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

import java.nio.ByteBuffer;

/**
 * @author Tang
 * @classname NettyDecoder
 * @description [ 解码器 ]
 * @date 2022/12/11 18:35
 */
public class NettyDecoder extends LengthFieldBasedFrameDecoder {

    public NettyDecoder() {
        super(16777216, 0, 4,0,4);
    }

    @Override
    protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
        ByteBuf frame = (ByteBuf)super.decode(ctx, in);
        ByteBuffer byteBuffer = frame.nioBuffer();
        return RemotingCommand.decoder(byteBuffer);
    }
}
